import { defineStore } from 'pinia'
import { IPageInfo } from '../utils/page_info'
import { getTagInfoList, getUserInfoList, ITag, IUserInfo } from './api'

export const useTagStore = defineStore('tag', {
  state: () => {
    return {
      tags: [{} as ITag],
    }
  },
  getters: {},
  actions: {
    async getAllTags() {
      await getTagInfoList({ pageInfo: { page: 1, pageSize: 9999 }, tagInfo: {} as ITag }).then(resp => {
        this.tags.length = 0 // 先清空
        this.tags.push(...resp.data.data)
      })
    },
  },
})

export const useUserStore = defineStore('user', {
  state: () => {
    return {
      users: [{} as IUserInfo], // 当前页用户
      total: 0, // 总数
    }
  },
  actions: {
    async getUsers(pageInfo: IPageInfo, searchInfo: IUserInfo) {
      await getUserInfoList({ pageInfo: pageInfo, userInfo: searchInfo }).then(resp => {
        this.users.length = 0 // 先清空
        this.users.push(...resp.data.data)
        this.total = resp.data.total // 总数据量
      })
    },
  },
})
